package com.xtreme.test
/*
 * This code is copied from the following Blog post:
 * http://gleichmann.wordpress.com/2010/11/28/high-higher-higher-order-functions/
 * 
 * 
 * 
 * 
 */

object FilterHigherOrder {
  
/*  val filterEven  =  ( xs :List[Int] )  => {
    val even= (x:Int) => x%2==0

    for(  x <- xs;   if even(x)  )  yield x
}
  val filterOdd=(xs:List[Int]) => {
    val odd=(x:Int) => x%2==1
    for(x<-xs; if odd(x)) yield x
  }
*/  
  val filterOp=(predicate:Int =>Boolean,xs:List[Int]) => {
    for(x<-xs;if predicate(x)) yield x
  }
   def main(args: Array[String]) {
     val values=List(1,2,3,4,5)
     val evenValues=filterOp((x:Int)=> x%2==0,values)
     val oddValues=filterOp((x:Int)=> x%2==1,values)
     print(evenValues.mkString+"**Odd Values**"+oddValues.mkString)
    
    }

}